﻿// -----------------------------------------------------------------------
// <copyright file="VideoPlayer.cs" company="Abyssalsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Core.Player.Video
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;

    /// <summary>
    /// Concrete implementation of Player
    /// </summary>
    internal class VideoPlayer : Player
    {
        /// <summary> Initializes a new instance of the VideoPlayer class. </summary>
        internal VideoPlayer()
        {
        }

        /// <summary>
        /// Open file
        /// </summary>
        /// <param name="file">The file path to open</param>
        /// <param name="fileType">The file type of the file</param>
        internal override void Open(string file, Helper.FileTypeEnum fileType)
        {
            // Call before open event
            if (Events.Instance.BeforeOpen != null)
            {
                Events.Instance.BeforeOpen(null, null);
            }

            MediaInfo.FilePath = file;

            Render.Instance.Open();
            if (Events.Instance.Open != null)
            {
                Events.Instance.Open(null, null);
            }
        }

        /// <summary>Play media file</summary>
        internal override void Play()
        {
            // Update file name
            MediaInfo.FileName = System.IO.Path.GetFileNameWithoutExtension(MediaInfo.FilePath);

            Render.Instance.Play();
            if (Events.Instance.Play != null)
            {
                Events.Instance.Play(null, null);
            }
        }

        /// <summary>Pause playback</summary>
        internal override void Pause()
        {
            Render.Instance.Pause();
            if (Events.Instance.Pause != null)
            {
                Events.Instance.Pause(null, null);
            }
        }

        /// <summary>Stop playback</summary>
        internal override void Stop()
        {
            Render.Instance.Stop(this, null);
            if (Events.Instance.Stop != null)
            {
                Events.Instance.Stop(null, null);
            }
        }

        /// <summary>Set audio volume</summary>
        /// <param name="value">New volume</param>
        internal override void SetVolume(int value)
        {
            Status.Volume = value;

            Render.Instance.SetVolume();
            if (Events.Instance.VolumeChanged != null)
            {
                Events.Instance.VolumeChanged(null, null);
            }
        }

        /// <summary>Seek current media to specified position</summary>
        /// <param name="value">New position value</param>
        internal override void Seek(int value)
        {
            Render.Instance.Seek(value);

            if (Events.Instance.Seeking != null)
            {
                Events.Instance.Seeking(null, null);
            }
        }

        /// <summary>Resume current playback</summary>
        internal override void Resume()
        {
            Render.Instance.Resume();

            if (Events.Instance.Resume != null)
            {
                Events.Instance.Resume(null, null);
            }
        }

        /// <summary>Switch video full screen mode</summary>
        internal override void SetVideoFullscreen()
        {
            //Render.Instance.ToggleFullScreen();
        }

        /// <summary>Release any resources used</summary>
        internal override void Dispose()
        {
            Events.Instance.Dispose(null, null);
        }

        /// <summary>
        /// Calculates the total time of the media in seconds
        /// </summary>
        /// <returns>Returns the total time transformed in seconds</returns>
        internal override double GetTotalTimeInSeconds()
        {
            return Render.Instance.GetTotalTimeInSeconds();
        }

        /// <summary>
        /// Calculates the total time of the media in bytes
        /// </summary>
        /// <returns>Returns the total time transformed in bytes</returns>
        internal override long GetTotalTimeInBytes()
        {
            return Render.Instance.GetTotalTimeInBytes();
        }

        /// <summary>
        /// Calculates the current position of the media in seconds
        /// </summary>
        /// <returns>Returns the current position transformed in seconds</returns>
        internal override double GetCurrentPositionInSeconds()
        {
            return Render.Instance.GetCurrentPositionInSeconds();
        }

        /// <summary>
        /// Calculates the current position of the media in bytes
        /// </summary>
        /// <returns>Returns the current position transformed in bytes</returns>
        internal override long GetCurrentPositionInBytes()
        {
            return Render.Instance.GetCurrentPositionInBytes();
        }

        /// <summary>
        /// Calculates the total time of the media formatted
        /// </summary>
        /// <returns>Returns the total time of the current playback formatted</returns>
        internal override string GetTotalTimeFormatted()
        {
            return Render.Instance.GetTotalTimeFormatted();
        }

        /// <summary>
        /// Calculates the current position of the media formatted
        /// </summary>
        /// <returns>Returns the current position of the current playback formatted</returns>
        internal override string GetCurrentPositionFormatted()
        {
            return Render.Instance.GetCurrentPositionFormatted();
        }
    }
}
